package com.culture.web.controller.AI.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.culture.system.domain.ChatMessages;
import com.culture.system.service.IChatMessagesService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.culture.common.annotation.Log;
import com.culture.common.core.controller.BaseController;
import com.culture.common.core.domain.AjaxResult;
import com.culture.common.enums.BusinessType;
import com.culture.common.utils.poi.ExcelUtil;
import com.culture.common.core.page.TableDataInfo;

/**
 * AI聊天Controller
 *
 * @author lidongsheng
 * @date 2025-04-10
 */
@RestController
@RequestMapping("/AI/AiChat")
public class ChatMessagesController extends BaseController
{
    @Autowired
    private IChatMessagesService chatMessagesService;

    /**
     * 查询AI聊天列表
     */
    @PreAuthorize("@ss.hasPermi('AI:AiChat:list')")
    @GetMapping("/list")
    public TableDataInfo list(ChatMessages chatMessages)
    {
        startPage();
        List<ChatMessages> list = chatMessagesService.selectChatMessagesList(chatMessages);
        return getDataTable(list);
    }

    /**
     * 导出AI聊天列表
     */
    @PreAuthorize("@ss.hasPermi('AI:AiChat:export')")
    @Log(title = "AI聊天", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ChatMessages chatMessages)
    {
        List<ChatMessages> list = chatMessagesService.selectChatMessagesList(chatMessages);
        ExcelUtil<ChatMessages> util = new ExcelUtil<ChatMessages>(ChatMessages.class);
        util.exportExcel(response, list, "AI聊天数据");
    }

    /**
     * 获取AI聊天详细信息
     */
    @PreAuthorize("@ss.hasPermi('AI:AiChat:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(chatMessagesService.selectChatMessagesById(id));
    }

    /**
     * 新增AI聊天
     */
    @PreAuthorize("@ss.hasPermi('AI:AiChat:add')")
    @Log(title = "AI聊天", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ChatMessages chatMessages)
    {
        return toAjax(chatMessagesService.insertChatMessages(chatMessages));
    }

    /**
     * 修改AI聊天
     */
    @PreAuthorize("@ss.hasPermi('AI:AiChat:edit')")
    @Log(title = "AI聊天", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ChatMessages chatMessages)
    {
        return toAjax(chatMessagesService.updateChatMessages(chatMessages));
    }

    /**
     * 删除AI聊天
     */
    @PreAuthorize("@ss.hasPermi('AI:AiChat:remove')")
    @Log(title = "AI聊天", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(chatMessagesService.deleteChatMessagesByIds(ids));
    }
}
